//package pms.test;
//import pms.Biz.EmpBiz;
//import pms.Biz.MedicineBiz;
//import pms.Biz.SaleBiz;
//import pms.Biz.impl.CustomerBizImpl;
//import pms.Biz.impl.EmpBizImpl;
//import pms.Biz.impl.MedicineBizImpl;
//import pms.Biz.impl.SaleBizImpl;
//
//import pms.entity.Customer;
//import pms.entity.Emp;
//import pms.entity.Medicine;
//import pms.entity.Sale;
//
//import java.time.LocalDate;
//
//import java.util.List;
//import java.util.Scanner;
//public class APP {
//    public static Emp loginemp;
//    public static void main(String[] args) {
//        Scanner scanner=new Scanner(System.in);
//        System.out.println("欢迎进入人事系统！！！，请先登录");
//        System.out.print("请输入你的登录账号:");
//        String lname=scanner.next();
//        System.out.print("请输入你的登录密码:");
//        String pwd=scanner.next();
//
//        //调用登录业务
//        EmpBiz biz=new EmpBizImpl();
//        Emp emp=  biz.checkLogin(lname,pwd);
//        if(emp!=null){
//            if(emp.getEmp_status().equals("激活")){
//
//                System.out.println("登录成功！");
//                APP.loginemp=emp;//将用户保存到登录用户的对象中
//                switch(emp.getEmp_role()){
//                    case "":
//                        //CEO操作的代码
//                        System.out.println("欢迎你，我最尊敬的老板"+emp.getEmp_rname());
//                        break;
//                    case "人事经理":
//                        //人事经理操作的代码
//                        System.out.println("欢迎你，人事经理"+emp.getEmp_rname());
//                        break;
//                    case "部门经理":
//                        //部门经理操作的代码
//                        System.out.println("欢迎你，部门经理"+emp.getEmp_rname());
//                        break;
//                    default:
//                        boolean flag=true;
//                        while(flag){
//                            //普通操作的代码
//                            System.out.println("欢迎你，普通员工"+emp.getEmp_rname());
//                            System.out.println("按1 药品查询");
//                            System.out.println("按2 登记销售记录");
//                            System.out.println("按3 查看或添加客户资料");
//                            System.out.println("按4 处理退货");
//                            System.out.println("按5 退出登录");
//                            String input =scanner.next();
//                            switch (input){
//                                case "1":
//                                    System.out.println("进入药品查询");
//                                    System.out.println("请输入要查询的药品名称");
//                                    Scanner scanner1=new Scanner(System.in);
//                                    String medicinename=scanner1.next();
//                                    MedicineBiz biz1=new MedicineBizImpl();
//                                    List<Medicine> medicine=null;
//                                    if( (medicine=biz1.qurryMedicine(medicinename))!=null){
//                                        for (Medicine medi:medicine){
//                                            System.out.println("药品id："+medi.getMedicine_id()+" 药品名称："+medi.getMedicine_name()+" 药品单价："+medi.getMedicine_price()+
//                                                    " 药品有效期："+medi.getMedicine_date()+" 库存数量："+medi.getMedicine_number());
//                                        }
//                                    }else{
//                                        System.out.println("输入的药品名称有误，请重新输入");
//                                    }
//                                    break;
//                                case "2":
//                                    Scanner scanner2=new Scanner(System.in);
//                                    SaleBiz biz2=new SaleBizImpl();
//                                    Sale sale=new Sale();
//                                    System.out.println("进入登记销售记录，开始登记您的销售记录");
//                                    System.out.println("请输入客户的联系方式");
//                                    String customertel=scanner2.next();
//                                    System.out.println("请输入药品id");
//                                    int medicineid1=scanner2.nextInt();
//                                    System.out.println("请输入销售数量");
//                                    int salenumber=scanner2.nextInt();
//
//                                    sale.setSale_number(salenumber);
//                                    sale.setSale_date(LocalDate.now());
//                                    sale.setSale_emp(APP.loginemp);
////                                    CustomerDao dao=new CustomerDaoImpl();
////                                    Customer customer=dao.queryCustomerBytel(customertel);
////                                    sale.setSale_customer(customer);
//                                    CustomerBiz biz3=new CustomerBizImpl();
//                                    Customer customer=biz3.qurryCustomerByTel(customertel);
//                                    sale.setSale_customer(customer);
////                                    MedicineDao dao1=new MedicineDaoImpl();
////                                    Medicine medicine1=dao1.qurryMedicineByID(medicinneid1);
////                                    sale.setSale_medicine(medicine1);
//                                    MedicineBiz biz4=new MedicineBizImpl();
////                                    Medicine medicine1=biz4.qurryNumber(medicinneid1);
//                                    Medicine medicine1=biz4.qurryMedicine(medicineid1);
//                                    sale.setSale_medicine(medicine1);
//                                    biz4.downMedicineNumber(medicine1.getMedicine_id(),salenumber);
//                                    Double saleamount=medicine1.getMedicine_price()*salenumber;
//                                    Double realsaleamount=0.0;
//                                    if (customer.getCustomer_tel().equals("普通会员")){
//                                        realsaleamount=saleamount*0.95;
//                                    }else if (customer.getCustomer_tel().equals("高级会员")){
//                                        realsaleamount=saleamount*0.9;
//                                    }else if (customer.getCustomer_tel().equals("超级会员")){
//                                        realsaleamount=saleamount*0.8;
//                                    }else {
//                                        realsaleamount=saleamount;
//                                    }
//                                    sale.setSale_amount(realsaleamount);
//
//                                    SaleBiz biz5=new SaleBizImpl();
//                                    if(biz5.addsaleForLeave(sale)){
//                                        System.out.println("登记销售记录成功");
//                                    }
//                                    else{
//                                        System.out.println("登记销售记录失败");
//                                    }
//                                    break;
//                                case "3":
//                                    Scanner scanner3=new Scanner(System.in);
//                                    System.out.println("进入查看或添加客户资料");
//                                    System.out.println("请输入客户联系方式，查看是否存在客户资料");
//                                    String tel=scanner3.next();
//                                    CustomerBiz biz6=new CustomerBizImpl();
//                                    Customer customer1=null;
//                                    if ((customer1=biz6.qurryCustomerByTel(tel))!=null){
//                                        System.out.println("该客户资料如下");
//                                        System.out.println("客户id"+customer1.getCustomer_id()+"客户姓名"+customer1.getCustomer_name()+"客户联系方式"+customer1.getCustomer_tel()+"客户会员等级"+customer1.getCustomer_level());
//                                    }else {
//                                        System.out.println("不存在该客户资料，开始添加该客户资料");
//                                        System.out.println("请输入客户姓名");
//                                        String customername=scanner3.next();
//                                        System.out.println("请输入客户联系方式");
//                                        String customertel1=scanner3.next();
//                                        System.out.println("请输入客户会员等级(普通会员/高级会员/超级会员)");
//                                        String customerlevel=scanner3.next();
//                                        customer1.setCustomer_name(customername);
//                                        customer1.setCustomer_tel(customertel1);
//                                        customer1.setCustomer_level(customerlevel);
//                                        if(biz6.addCustomer(customer1)){
//                                            System.out.println("添加客户资料成功");
//                                        }
//                                        else{
//                                            System.out.println("添加客户资料失败");
//                                        }
//                                    }
//                                    break;
//                                case "4":
//                                    System.out.println("进入处理退货");
//                                    System.out.println("请输入顾客要退货的药品id");
//                                    Scanner scanner4=new Scanner(System.in);
//                                    int medicineid=scanner4.nextInt();
//                                    System.out.println("请输入顾客的联系方式");
//                                    String customertel1=scanner4.next();
//                                    System.out.println("请输入此药品的退货数量");
//                                    int medicinenumber=scanner4.nextInt();
//                                    CustomerBiz biz7=new CustomerBizImpl();
//                                    Customer customer2=biz7.qurryCustomerByTel(customertel1);
//                                    MedicineBiz biz8=new MedicineBizImpl();
//                                    Medicine medicine2=biz8.qurryMedicine(medicineid);
//                                    biz8.upMedicineNumber(medicine2.getMedicine_id(),medicinenumber);
//                                    SaleBiz biz9=new SaleBizImpl();
//                                    if(biz9.deletesale(medicineid,customer2.getCustomer_id(),APP.loginemp.getEmp_id())){
//                                        System.out.println("退货操作成功");
//                                    }
//                                    else{
//                                        System.out.println("退货操作失败");
//                                    }
//                                    break;
//                                case "5":
//                                    //注销用户
//                                    APP.loginemp=null;
//                                    flag=false;
//                                    System.out.println("退出登录！！！");
//                                    break;
//                                default:
//                                    break;
//                            }
//
//                        }
//
//                        break;
//                }
//            }else if(emp.getEmp_status().equals("禁用")){
//                System.out.println("您当前的账号已经被禁用，请找管理员解禁");
//            }else{
//                System.out.println("当前账户的用户已经离职，无法登录");
//            }
//
//
//        }else{
//            System.out.println("账号或者密码错误！！！");
//        }
//    }
//
//
//}
        //普通操作的代码
package pms.test;

import pms.Biz.*;
import pms.Biz.impl.*;
import pms.entity.*;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Scanner;

    public class APP {
        public static Emp loginemp;
        public static void main(String[] args) {
            boolean a=true;
            while (a) {
                Scanner scanner = new Scanner(System.in);
                System.out.println("欢迎进入药店管理系统，请先登录");
                System.out.println("按1 开始登录");
                System.out.println("按0 退出系统");
                System.out.println("请输入你的选项：");
                int choose=scanner.nextInt();
                switch (choose) {
                    case 1:
                        System.out.print("请输入你的登录账号:");
                        String lname = scanner.next();
                        System.out.print("请输入你的登录密码:");
                        String pwd = scanner.next();
                        //调用登录业务
                        EmpBiz biz = new EmpBizImpl();
                        Emp emp = biz.checkLogin(lname, pwd);
                        String record1,record2,record3,record4,record5,record6,record7;
                        APP.loginemp=emp;
                        if (emp != null) {
                            if (emp.getEmp_status().equals("激活")){
                                System.out.println("登录成功");
                                a=false;
                                switch (emp.getEmp_role()){
                                    case "系统管理员":
                                        boolean ab=true;
                                        while (ab){
                                            System.out.println("欢迎系统管理员"+emp.getEmp_rname());
                                            System.out.println("0 退出系统");
                                            System.out.println("1 账号创建");
                                            System.out.println("2 信息管理");
                                            System.out.println("3 系统日志");
                                            System.out.println("4 数据备份");
                                            System.out.println("请输入你的选择：");
                                            int b=scanner.nextInt();
                                            RecordBiz recordBiz=new RecordBizImpl();
                                            String time=recordBiz.getTime();
                                            switch (b){
                                                case 0:
                                                    ab=false;
                                                    break;
                                                case 1:
                                                    System.out.println("请输入员工姓名：");
                                                    String rname=scanner.next();
                                                    System.out.println("请输入员工性别：");
                                                    String sex=scanner.next();
                                                    System.out.println("请输入员工职务：");
                                                    String role=scanner.next();
                                                    System.out.println("请输入创建的账号：");
                                                    String cname=scanner.next();
                                                    System.out.println("请输入创建的账号密码：");
                                                    String cpwd=scanner.next();
                                                    System.out.println("请再次输入创建的账号密码：");
                                                    String cpwd2=scanner.next();
                                                    if (cpwd.equals(cpwd2)){
                                                        Emp emp1=new Emp();
                                                        emp1.setEmp_rname(rname);
                                                        emp1.setEmp_sex(sex);
                                                        emp1.setEmp_role(role);
                                                        emp1.setEmp_lname(cname);
                                                        emp1.setEmp_lpwd(cpwd2);
                                                        emp1.setEmp_status("激活");
                                                        EmpBiz empBiz=new EmpBizImpl();
                                                        if (empBiz.addEmp(emp1)){
                                                            System.out.println("创建成功");
                                                            record1="创建了一个账号";
                                                            Record record=new Record();
                                                            record.setRecord_time(time);
                                                            record.setRecord_content(record1);
                                                            record.setRecord_user(emp.getEmp_rname());
                                                            recordBiz.addRecord(record);
                                                            break;
                                                        }else {
                                                            System.out.println("创建失败");
                                                            break;
                                                        }
                                                    }else {
                                                        System.out.println("账号创建失败，两次密码不相同");
                                                    }
                                                    break;
                                                case 2:
                                                    System.out.println("注意账号不可修改！！！");
                                                    List<Emp> emplist=biz.getAllEmp();
                                                    for(int i=0;i<emplist.size();i++){
                                                        System.out.println("员工序号:"+i+" "+emplist.get(i));
                                                    }
                                                    System.out.println("请选择要编辑的员工的序号");
                                                    Scanner s=new Scanner(System.in);
                                                    int index= s.nextInt();
                                                    Emp emp1=emplist.get(index);
                                                    Scanner s2=new Scanner(System.in);
                                                    System.out.println("请输入修改后的姓名（如果不修改直接回车）");
                                                    String rname2=s2.nextLine();
                                                    if(rname2!=null&&!rname2.equals("")){
                                                        emp1.setEmp_rname(rname2);
                                                        record2="修改了账号为"+emp1.getEmp_lname()+"的姓名";
                                                        Record record=new Record();
                                                        record.setRecord_time(time);
                                                        record.setRecord_user(emp.getEmp_rname());
                                                        record.setRecord_content(record2);
                                                        recordBiz.addRecord(record);
                                                    }
                                                    System.out.println("请输入修改后的密码（如果不修改直接回车）");
                                                    String pwd2=s2.nextLine();
                                                    if(pwd2!=null&&!pwd2.equals("")){
                                                        emp1.setEmp_lpwd(pwd2);
                                                        record3="修改了账号为"+emp1.getEmp_lname()+"的密码";
                                                        Record record=new Record();
                                                        record.setRecord_time(time);
                                                        record.setRecord_user(emp.getEmp_rname());
                                                        record.setRecord_content(record3);
                                                        recordBiz.addRecord(record);
                                                    }
                                                    System.out.println("请输入修改后的性别（如果不修改直接回车）");
                                                    String sex2=s2.nextLine();
                                                    if(sex2!=null&&!sex2.equals("")){
                                                        emp1.setEmp_sex(sex2);
                                                        record4="修改了账号为"+emp1.getEmp_lname()+"的性别";
                                                        Record record=new Record();
                                                        record.setRecord_time(time);
                                                        record.setRecord_user(emp.getEmp_rname());
                                                        record.setRecord_content(record4);
                                                        recordBiz.addRecord(record);
                                                    }
                                                    System.out.println("请输入修改后的职务（如果不修改直接回车）");
                                                    String role2=s2.nextLine();
                                                    if(role2!=null&&!role2.equals("")){
                                                        emp1.setEmp_role(role2);
                                                        record5="修改了账号为"+emp1.getEmp_lname()+"的职务";
                                                        Record record=new Record();
                                                        record.setRecord_time(time);
                                                        record.setRecord_user(emp.getEmp_rname());
                                                        record.setRecord_content(record5);
                                                        recordBiz.addRecord(record);
                                                    }
                                                    System.out.println("请选择修改后的账号状态");
                                                    System.out.println("1 激活");
                                                    System.out.println("2 禁用");
                                                    System.out.println("3 不修改");
                                                    int d=s2.nextInt();
                                                    String status2="激活";
                                                    if (d==1){
                                                        status2="激活";
                                                        record6="激活了账号"+emp1.getEmp_lname();
                                                        Record record=new Record();
                                                        record.setRecord_time(time);
                                                        record.setRecord_user(emp.getEmp_rname());
                                                        record.setRecord_content(record6);
                                                        recordBiz.addRecord(record);
                                                    }else if (d==2){
                                                        status2="禁用";
                                                        record7="禁用了账号"+emp1.getEmp_lname();
                                                        Record record=new Record();
                                                        record.setRecord_time(time);
                                                        record.setRecord_user(emp.getEmp_rname());
                                                        record.setRecord_content(record7);
                                                        recordBiz.addRecord(record);
                                                    }else if (d==3){
                                                        status2=emp1.getEmp_status();
                                                    } else {
                                                        System.out.println("无效操作！");
                                                    }
                                                    if(status2!=null&&!status2.equals("")){
                                                        emp1.setEmp_status(status2);
                                                    }
                                                    if (biz.editEmp(emp1)){
                                                        System.out.println("修改成功！");
                                                    }else {
                                                        System.out.println("修改失败！");
                                                    }
                                                    break;
                                                case 3:
                                                    System.out.println("1 查看系统日志");
                                                    System.out.println("2 清理系统日志");
                                                    System.out.println("请输入你的操作选择：");
                                                    List<Record> recordList=recordBiz.getAllRecord();
                                                    int a1=scanner.nextInt();
                                                    switch (a1){
                                                        case 1:
                                                            System.out.println("                       ---------------系统日志---------------");
                                                            if (recordList.size()==0){
                                                                System.out.println("暂无数据");
                                                            }else {
                                                                for (int j=0;j<recordList.size();j++){
                                                                    System.out.println(recordList.get(j));
                                                                }}
                                                            break;
                                                        case 2:
                                                            System.out.println("确定清空系统日志数据吗？");
                                                            System.out.println("1 确定清空");
                                                            System.out.println("2 取消操作");
                                                            System.out.println("请输入你的操作选择：");
                                                            int a2=scanner.nextInt();
                                                            switch (a2){
                                                                case 1:
                                                                    if (recordBiz.deleteRecord(recordList)){
                                                                        System.out.println("系统日志清空成功！");
                                                                    }else {
                                                                        System.out.println("清空失败");
                                                                    }
                                                                    break;
                                                                case 2:
                                                                    System.out.println("取消成功！");
                                                                    break;
                                                            }
                                                            break;
                                                        default:
                                                            System.out.println("无效操作！");
                                                            break;
                                                    }
                                                    break;
                                                case 4:
                                                    RecordBiz recordBiz1=new RecordBizImpl();
                                                    List<Record> recordList1=recordBiz.getAllRecord();
                                                    EmpBiz empBiz=new EmpBizImpl();
                                                    List<Emp> empList=empBiz.getAllEmp();
                                                    List<Supplier> supplierList=recordBiz.getAllSupplier();
                                                    List<Medicine> medicineList=recordBiz.getAllMedicine();
                                                    List<Order> orderList=recordBiz.getAllOrder();
                                                    List<Sale> saleList=recordBiz.getAllSale();
                                                    List<Customer> customerList=recordBiz.getAllCustomer();
                                                    System.out.println("1 系统日志数据存档");
                                                    System.out.println("2 员工信息数据存档");
                                                    System.out.println("3 供应商信息数据存档");
                                                    System.out.println("4 药品信息数据存档");
                                                    System.out.println("5 采购订单数据存档");
                                                    System.out.println("6 销售记录数据存档");
                                                    System.out.println("7 客户信息数据存档");
                                                    System.out.println("请输入你的操作选择:");
                                                    int chi=scanner.nextInt();
                                                    switch (chi){
                                                        case 1:
                                                            File file=new File("D:/ab/系统日志数据");
                                                            if (file.exists()){
                                                                Scanner s1=new Scanner(System.in);
                                                                System.out.println("请输入本次备份的存档名词（不能与之前的相同否则会覆盖之前的数据）：");
                                                                String ad=s1.next()+".txt";
                                                                FileWriter fw=null;
                                                                BufferedWriter bw=null;
                                                                try {
                                                                    fw=new FileWriter("D:/ab/系统日志数据/"+ad,true);
                                                                    bw=new BufferedWriter(fw);
                                                                    for (int j=0;j<recordList1.size();j++) {
                                                                        bw.newLine();
                                                                        bw.write(recordList1.get(j).toString());
                                                                        bw.flush();
                                                                    }
                                                                    System.out.println("数据存档成功");
                                                                } catch (Exception e) {
                                                                    e.printStackTrace();
                                                                }finally {
                                                                    try {
                                                                        bw.close();
                                                                    } catch (IOException e) {
                                                                        e.printStackTrace();
                                                                    }
                                                                    try {
                                                                        fw.close();
                                                                    } catch (IOException e) {
                                                                        e.printStackTrace();
                                                                    }
                                                                }}else {
                                                                System.out.println("创建存档库成功，请再试一次。。。");
                                                                file.mkdirs();
                                                            }
                                                            break;
                                                        case 2:
                                                            File file1=new File("D:/ab/员工信息数据");
                                                            if (file1.exists()){
                                                                Scanner s3=new Scanner(System.in);
                                                                System.out.println("请输入本次备份的存档名词（不能与之前的相同否则会覆盖之前的数据）：");
                                                                String ad1=s3.next()+".txt";
                                                                FileWriter fw1=null;
                                                                BufferedWriter bw1=null;
                                                                try {
                                                                    fw1=new FileWriter("D:/ab/员工信息数据/"+ad1,true);
                                                                    bw1=new BufferedWriter(fw1);
                                                                    for (int j=0;j<empList.size();j++) {
                                                                        bw1.newLine();
                                                                        bw1.write(empList.get(j).toString());
                                                                        bw1.flush();
                                                                    }
                                                                    System.out.println("数据存档成功");
                                                                } catch (Exception e) {
                                                                    e.printStackTrace();
                                                                }finally {
                                                                    try {
                                                                        bw1.close();
                                                                    } catch (IOException e) {
                                                                        e.printStackTrace();
                                                                    }
                                                                    try {
                                                                        fw1.close();
                                                                    } catch (IOException e) {
                                                                        e.printStackTrace();
                                                                    }
                                                                }}else {
                                                                System.out.println("创建存档库成功，请再试一次。。。");
                                                                file1.mkdirs();
                                                            }
                                                            break;
                                                        case 3:
                                                            File file2=new File("D:/ab/供应商信息数据");
                                                            if (file2.exists()){
                                                                Scanner s3=new Scanner(System.in);
                                                                System.out.println("请输入本次备份的存档名词（不能与之前的相同否则会覆盖之前的数据）：");
                                                                String ad2=s3.next()+".txt";
                                                                FileWriter fw1=null;
                                                                BufferedWriter bw1=null;
                                                                try {
                                                                    fw1=new FileWriter("D:/ab/供应商信息数据/"+ad2,true);
                                                                    bw1=new BufferedWriter(fw1);
                                                                    for (int j=0;j<supplierList.size();j++) {
                                                                        bw1.newLine();
                                                                        bw1.write(supplierList.get(j).toString());
                                                                        bw1.flush();
                                                                    }
                                                                    System.out.println("数据存档成功");
                                                                } catch (Exception e) {
                                                                    e.printStackTrace();
                                                                }finally {
                                                                    try {
                                                                        bw1.close();
                                                                    } catch (IOException e) {
                                                                        e.printStackTrace();
                                                                    }
                                                                    try {
                                                                        fw1.close();
                                                                    } catch (IOException e) {
                                                                        e.printStackTrace();
                                                                    }
                                                                }}else {
                                                                System.out.println("创建存档库成功，请再试一次。。。");
                                                                file2.mkdirs();
                                                            }
                                                            break;
                                                        case 4:
                                                            File file3=new File("D:/ab/药品信息数据");
                                                            if (file3.exists()){
                                                                Scanner s3=new Scanner(System.in);
                                                                System.out.println("请输入本次备份的存档名词（不能与之前的相同否则会覆盖之前的数据）：");
                                                                String ad3=s3.next()+".txt";
                                                                FileWriter fw1=null;
                                                                BufferedWriter bw1=null;
                                                                try {
                                                                    fw1=new FileWriter("D:/ab/药品信息数据/"+ad3,true);
                                                                    bw1=new BufferedWriter(fw1);
                                                                    for (int j=0;j<medicineList.size();j++) {
                                                                        bw1.newLine();
                                                                        bw1.write(medicineList.get(j).toString());
                                                                        bw1.flush();
                                                                    }
                                                                    System.out.println("数据存档成功");
                                                                } catch (Exception e) {
                                                                    e.printStackTrace();
                                                                }finally {
                                                                    try {
                                                                        bw1.close();
                                                                    } catch (IOException e) {
                                                                        e.printStackTrace();
                                                                    }
                                                                    try {
                                                                        fw1.close();
                                                                    } catch (IOException e) {
                                                                        e.printStackTrace();
                                                                    }
                                                                }}else {
                                                                System.out.println("创建存档库成功，请再试一次。。。");
                                                                file3.mkdirs();
                                                            }
                                                            break;
                                                        case 5:
                                                            File file4=new File("D:/ab/采购订单数据");
                                                            if (file4.exists()){
                                                                Scanner s3=new Scanner(System.in);
                                                                System.out.println("请输入本次备份的存档名词（不能与之前的相同否则会覆盖之前的数据）：");
                                                                String ad3=s3.next()+".txt";
                                                                FileWriter fw1=null;
                                                                BufferedWriter bw1=null;
                                                                try {
                                                                    fw1=new FileWriter("D:/ab/药品信息数据/"+ad3,true);
                                                                    bw1=new BufferedWriter(fw1);
                                                                    for (int j=0;j<orderList.size();j++) {
                                                                        bw1.newLine();
                                                                        bw1.write(orderList.get(j).toString());
                                                                        bw1.flush();
                                                                    }
                                                                    System.out.println("数据存档成功");
                                                                } catch (Exception e) {
                                                                    e.printStackTrace();
                                                                }finally {
                                                                    try {
                                                                        bw1.close();
                                                                    } catch (IOException e) {
                                                                        e.printStackTrace();
                                                                    }
                                                                    try {
                                                                        fw1.close();
                                                                    } catch (IOException e) {
                                                                        e.printStackTrace();
                                                                    }
                                                                }}else {
                                                                System.out.println("创建存档库成功，请再试一次。。。");
                                                                file4.mkdirs();
                                                            }
                                                            break;
                                                        case 6:
                                                            File file5=new File("D:/ab/销售记录数据");
                                                            if (file5.exists()){
                                                                Scanner s3=new Scanner(System.in);
                                                                System.out.println("请输入本次备份的存档名词（不能与之前的相同否则会覆盖之前的数据）：");
                                                                String ad4=s3.next()+".txt";
                                                                FileWriter fw1=null;
                                                                BufferedWriter bw1=null;
                                                                try {
                                                                    fw1=new FileWriter("D:/ab/销售记录数据/"+ad4,true);
                                                                    bw1=new BufferedWriter(fw1);
                                                                    for (int j=0;j<saleList.size();j++) {
                                                                        bw1.newLine();
                                                                        bw1.write(saleList.get(j).toString());
                                                                        bw1.flush();
                                                                    }
                                                                    System.out.println("数据存档成功");
                                                                } catch (Exception e) {
                                                                    e.printStackTrace();
                                                                }finally {
                                                                    try {
                                                                        bw1.close();
                                                                    } catch (IOException e) {
                                                                        e.printStackTrace();
                                                                    }
                                                                    try {
                                                                        fw1.close();
                                                                    } catch (IOException e) {
                                                                        e.printStackTrace();
                                                                    }
                                                                }}else {
                                                                System.out.println("创建存档库成功，请再试一次。。。");
                                                                file5.mkdirs();
                                                            }
                                                            break;
                                                        case 7:
                                                            File file6=new File("D:/ab/客户信息数据");
                                                            if (file6.exists()){
                                                                Scanner s3=new Scanner(System.in);
                                                                System.out.println("请输入本次备份的存档名词（不能与之前的相同否则会覆盖之前的数据）：");
                                                                String ad5=s3.next()+".txt";
                                                                FileWriter fw1=null;
                                                                BufferedWriter bw1=null;
                                                                try {
                                                                    fw1=new FileWriter("D:/ab/客户信息数据/"+ad5,true);
                                                                    bw1=new BufferedWriter(fw1);
                                                                    for (int j=0;j<customerList.size();j++) {
                                                                        bw1.newLine();
                                                                        bw1.write(customerList.get(j).toString());
                                                                        bw1.flush();
                                                                    }
                                                                    System.out.println("数据存档成功");
                                                                } catch (Exception e) {
                                                                    e.printStackTrace();
                                                                }finally {
                                                                    try {
                                                                        bw1.close();
                                                                    } catch (IOException e) {
                                                                        e.printStackTrace();
                                                                    }
                                                                    try {
                                                                        fw1.close();
                                                                    } catch (IOException e) {
                                                                        e.printStackTrace();
                                                                    }
                                                                }}else {
                                                                System.out.println("创建存档库成功，请再试一次。。。");
                                                                file6.mkdirs();
                                                            }
                                                            break;
                                                        default:
                                                            System.out.println("无效操作！");
                                                            break;
                                                    }
                                            }
                                        }
                                        break;
                                    case "采购员":
                                        boolean cnt=true;
                                        OrderBiz empBiz=new OrderBizImpl();
                                        while(cnt){
                                            System.out.println("欢迎你，采购员"+emp.getEmp_rname());
                                            System.out.println("按1 维护供应商信息（资质、联系方式、合作状态）");
                                            System.out.println("按2 生成采购计划、录入药品批次与价格");
                                            System.out.println("按3 根据库存阈值自动生成补货建议");
                                            System.out.println("按4 记录供应商报价并生成比价单");
                                            System.out.println("按5 质量问题药品退回供应商流程");
                                            System.out.println("按6 退出采购员账号");
                                            String input1=scanner.next();
                                            switch(input1){
                                                case "1":
                                                    boolean cnt2=true;
                                                    while (cnt2){
                                                    System.out.println("按A 查询供应商信息");
                                                    System.out.println("按B 修改供应商信息");
                                                    System.out.println("按C 退出当前功能");
                                                        String  input2=scanner.next();
                                                        switch(input2){
                                                            case "A":
                                                                System.out.println("请输入要查询的供应商的Id");
                                                                Integer supplier_id=scanner.nextInt();
                                                                System.out.println(empBiz.querySupplierInformationById(supplier_id));
                                                                break;
                                                            case "B":
                                                                System.out.println("请输入修改后的供应商的Id");
                                                                Integer supplier_id1=scanner.nextInt();
                                                                System.out.println("请输入修改后的供应商的名字");
                                                                String supplier_name=scanner.next();
                                                                System.out.println("请输入修改后的供应商的资质");
                                                                Integer supplier_qct=scanner.nextInt();
                                                                System.out.println("请输入修改后的供应商的电话");
                                                                String supplier_tel=scanner.next();
                                                                System.out.println("请输入修改后的供应商的状态");
                                                                String supplier_status=scanner.next();
                                                                System.out.println("请输入修改后的供应商的提供的药品的Id");
                                                                Integer supplier_mainMedicine=scanner.nextInt();
                                                                System.out.println("请输入修改后的供应商的药品的价格");
                                                                Integer supplier_price=scanner.nextInt();
                                                                if(empBiz.updateSupplierInformationById(supplier_id1
                                                                        , supplier_name
                                                                        , supplier_qct
                                                                        , supplier_tel
                                                                        , supplier_status
                                                                        , supplier_mainMedicine
                                                                        , supplier_price)){
                                                                    System.out.println("修改成功");
                                                                }
                                                                break;
                                                            case "C":
                                                                cnt2=false;
                                                                break;
                                                        }
                                                    }
                                                    break;
                                                case "2":
                                                    boolean cnt3=true;
                                                    while(cnt3){
                                                        System.out.println("按A 添加药品购物单");
                                                        System.out.println("按B 查询所需药品单");
                                                        System.out.println("按C 退出当前功能");
                                                        String input3=scanner.next();
                                                        switch (input3){
                                                            case "A":
                                                                System.out.println("请输入要添加的药品的供应商的Id");
                                                                Integer supplierid=scanner.nextInt();
                                                                Supplier supplier=empBiz.querySupplierInformationById(supplierid);
                                                                System.out.println("请输入添加的日期");
                                                                String order_date=scanner.next();
                                                                DateTimeFormatter df=DateTimeFormatter.ofPattern("yyyy-MM-dd");
                                                                LocalDate localDate=LocalDate.parse(order_date,df);
                                                                System.out.println("请输入要添加的药品的的数量");
                                                                Integer order_number=scanner.nextInt();
                                                                System.out.println("请输入要添加的药品的总价");
                                                                Integer order_amount=scanner.nextInt();
                                                                System.out.println("请输入要添加的药品的状态");
                                                                Integer order_status=scanner.nextInt();
                                                                if(empBiz.appendMedicineOrder(supplier,localDate,order_number,order_amount,order_status)){
                                                                    System.out.println("添加成功");
                                                                };
                                                                break;
                                                            case "B":
                                                                System.out.println(empBiz.queryMedicineOrder());
                                                                break;
                                                            case "C":
                                                                cnt3=false;
                                                                break;
                                                        }
                                                    }
                                                    break;
                                                case "3":
                                                    System.out.println("请输入要判断的药品的Id");
                                                    Integer medicine_id= scanner.nextInt();
                                                    if(empBiz.shortageOfMedicineAlertBYID(medicine_id)){
                                                        System.out.println("该药品需要补货");
                                                    }
                                                    break;
                                                case "4":
                                                    System.out.println("请输入要得到的最便宜价格的药品的Id");
                                                    Integer medicine_id1=scanner.nextInt();
                                                    System.out.println(empBiz.electTheBestSupplierByMedicineId(medicine_id1));
                                                    break;
                                                case "5":
                                                    System.out.println("请输入要删除的有问题的供应商的Id");
                                                    Integer supplier_id=scanner.nextInt();
                                                    if(empBiz.deleteQuestionSupplierById(supplier_id)){
                                                        System.out.println("修改成功");
                                                    }
                                                    break;
                                                case "6":
                                                    cnt=false;
                                                    break;
                                            }
                                        }
                                    case "普通员工":
                                        boolean flag=true;
                                        while(flag) {
                                            //普通操作的代码
                                            System.out.println("欢迎你，普通员工" + emp.getEmp_rname());
                                            System.out.println("按1 药品查询");
                                            System.out.println("按2 登记销售记录");
                                            System.out.println("按3 查看或添加客户资料");
                                            System.out.println("按4 处理退货");
                                            System.out.println("按5 退出登录");
                                            String input = scanner.next();
                                            switch (input) {
                                                case "1":
                                                    System.out.println("进入药品查询");
                                                    System.out.println("请输入要查询的药品名称");
                                                    Scanner scanner1 = new Scanner(System.in);
                                                    String medicinename = scanner1.next();
                                                    MedicineBiz biz1 = new MedicineBizImpl();
                                                    List<Medicine> medicine = null;
                                                    if ((medicine = biz1.qurryMedicine(medicinename)) != null) {
                                                        for (Medicine medi : medicine) {
                                                            System.out.println("药品id：" + medi.getMedicine_id() + " 药品名称：" + medi.getMedicine_name() + " 药品单价：" + medi.getMedicine_price() +
                                                                    " 药品有效期：" + medi.getMedicine_date() + " 库存数量：" + medi.getMedicine_number());
                                                        }
                                                    } else {
                                                        System.out.println("输入的药品名称有误，请重新输入");
                                                    }
                                                    break;
                                                case "2":
                                                    Scanner scanner2 = new Scanner(System.in);
                                                    SaleBiz biz2 = new SaleBizImpl();
                                                    Sale sale = new Sale();
                                                    System.out.println("进入登记销售记录，开始登记您的销售记录");
                                                    System.out.println("请输入客户的联系方式");
                                                    String customertel = scanner2.next();
                                                    System.out.println("请输入药品id");
                                                    int medicineid1 = scanner2.nextInt();
                                                    System.out.println("请输入销售数量");
                                                    int salenumber = scanner2.nextInt();

                                                    sale.setSale_number(salenumber);
                                                    sale.setSale_date(LocalDate.now());
                                                    sale.setSale_emp(pms.test.APP.loginemp);

//                                    CustomerDao dao=new CustomerDaoImpl();
//                                    Customer customer=dao.queryCustomerBytel(customertel);
//                                    sale.setSale_customer(customer);
                                                CustomerBiz biz3 = new CustomerBizImpl();
                                                Customer customer=new Customer();
                                                customer = biz3.qurryCustomerByTel(customertel);
                                                sale.setSale_customer(customer);
//                                    MedicineDao dao1=new MedicineDaoImpl();
//                                    Medicine medicine1=dao1.qurryMedicineByID(medicinneid1);
//                                    sale.setSale_medicine(medicine1);
                                                MedicineBiz biz4 = new MedicineBizImpl();
//                                    Medicine medicine1=biz4.qurryNumber(medicinneid1);
                                                Medicine medicine1 = biz4.qurryMedicine(medicineid1);
                                                sale.setSale_medicine(medicine1);
                                                biz4.downMedicineNumber(medicine1.getMedicine_id(), salenumber);
                                                Double saleamount = medicine1.getMedicine_price() * salenumber;
                                                Double realsaleamount = 0.0;
                                                if (customer.getCustomer_level()=="普通会员") {
                                                    realsaleamount = saleamount * 0.95;
                                                } else if (customer.getCustomer_level()=="高级会员") {
                                                    realsaleamount = saleamount * 0.9;
                                                } else if (customer.getCustomer_level()=="超级会员") {
                                                    realsaleamount = saleamount * 0.8;
                                                } else {
                                                    realsaleamount = saleamount;
                                                }
                                                sale.setSale_amount(realsaleamount);


                                                if (biz2.addsaleForLeave(sale)) {
                                                    System.out.println("登记销售记录成功");
                                                } else {
                                                    System.out.println("登记销售记录失败");
                                                }
                                                break;
                                            case "3":
                                                Scanner scanner3 = new Scanner(System.in);
                                                System.out.println("进入查看或添加客户资料");
                                                System.out.println("请输入客户联系方式，查看是否存在客户资料");
                                                String tel = scanner3.next();
                                                CustomerBiz biz6 = new CustomerBizImpl();
                                                Customer customer1 =null;
                                                if ((customer1 = biz6.qurryCustomerByTel(tel)) != null) {
                                                    System.out.println("该客户资料如下");
                                                    System.out.println("客户id" + customer1.getCustomer_id() + "客户姓名" + customer1.getCustomer_name() + "客户联系方式" + customer1.getCustomer_tel() + "客户会员等级" + customer1.getCustomer_level());
                                                } else {
                                                    System.out.println("不存在该客户资料，开始添加该客户资料");
                                                    Customer customer2=new Customer();
                                                    System.out.println("请输入客户姓名");
                                                    String customername = scanner3.next();
                                                    System.out.println("请输入客户联系方式");
                                                    String customertel1 = scanner3.next();
                                                    System.out.println("请输入客户会员等级(普通会员/高级会员/超级会员)");
                                                    String customerlevel = scanner3.next();
                                                    customer2.setCustomer_name(customername);
                                                    customer2.setCustomer_tel(customertel1);
                                                    customer2.setCustomer_level(customerlevel);
                                                    if (biz6.addCustomer(customer2)) {
                                                        System.out.println("添加客户资料成功");
                                                    } else {
                                                        System.out.println("添加客户资料失败");
                                                    }
                                                }
                                                break;
                                            case "4":
                                                System.out.println("进入处理退货");
                                                System.out.println("请输入顾客要退货的药品id");
                                                Scanner scanner4 = new Scanner(System.in);
                                                int medicineid = scanner4.nextInt();
                                                System.out.println("请输入顾客的联系方式");
                                                String customertel1 = scanner4.next();
                                                System.out.println("请输入此药品的退货数量");
                                                int medicinenumber = scanner4.nextInt();
                                                CustomerBiz biz7 = new CustomerBizImpl();
                                                Customer customer2=new Customer();
                                                customer2 = biz7.qurryCustomerByTel(customertel1);
                                                MedicineBiz biz8 = new MedicineBizImpl();
                                                Medicine medicine2=new Medicine();
                                                medicine2 = biz8.qurryMedicine(medicineid);
                                                biz8.upMedicineNumber(medicine2.getMedicine_id(), medicinenumber);
                                                SaleBiz biz9 = new SaleBizImpl();
                                                if (biz9.deletesale(medicineid, customer2.getCustomer_id(), pms.test.APP.loginemp.getEmp_id())) {
                                                    System.out.println("退货操作成功");
                                                } else {
                                                    System.out.println("退货操作失败");
                                                }
                                                break;
                                            case "5":
                                                //注销用户
                                                pms.test.APP.loginemp = null;
                                                flag = false;
                                                System.out.println("退出登录！！！");
                                                break;
                                            default:
                                                break;
                                        }
                                    }
                                    break;
                                case "库存管理员":
                                    MedicineBiz medicineBiz=new MedicineBizImpl();
                                    boolean kcgl=true;
                                    while (kcgl){
                                        System.out.println("欢迎库存管理员"+emp.getEmp_rname());
                                        medicineBiz.WarnMedicine();
                                        System.out.println("0 退出系统");
                                        System.out.println("1 库存更新");
                                        System.out.println("2 库存查看");
                                        System.out.println("请输入你的选择：");
                                        int kc=scanner.nextInt();
                                        switch (kc){
                                            case 0:
                                                kcgl=false;
                                                break;
                                            case 1:
                                                System.out.println("0 清理无用数据");
                                                System.out.println("1 添加新数据");
                                                System.out.println("2 更新数据");
                                                int kc1=scanner.nextInt();
                                                switch (kc1){
                                                    case 0:
                                                        System.out.println("请确认过期药品出库后执行清理数据操作");
                                                        System.out.println("是否继续执行？是/否");
                                                        Scanner s2=new Scanner(System.in);
                                                        if(s2.equals("是")){
                                                            if (medicineBiz.CleanUselessRecord()){
                                                                System.out.println("清理完成");
                                                            }else {
                                                                System.out.println("无需清理");
                                                            }
                                                            break;
                                                        }
                                                        else if (s2.equals("否")){
                                                            System.out.println("返回菜单");
                                                            break;
                                                        }
                                                        else {
                                                            System.out.println("无效字符");
                                                            break;
                                                        }
                                                    case 1:
                                                        Scanner s3=new Scanner(System.in);
                                                        System.out.println("请输入需添加的药品名：");
                                                        String name=s3.nextLine();
                                                        System.out.println("请输入需添加的药品单价：");
                                                        double price=s3.nextInt();
                                                        System.out.println("请输入需添加的药品日期（xxxx-xx-xx格式）：");
                                                        String date=s3.nextLine();
                                                        DateTimeFormatter df=DateTimeFormatter.ofPattern("yyyy年mm月dd日");
                                                        LocalDate date1=LocalDate.parse(date,df);
                                                        System.out.println("请输入药品数量：");
                                                        int number=s3.nextInt();
                                                        System.out.println("请输入药品数量阈值：");
                                                        int thd=s3.nextInt();

                                                        Medicine medicine=new Medicine();
                                                        medicine.setMedicine_name(name);
                                                        medicine.setMedicine_price(price);
                                                        medicine.setMedicine_date(date1);
                                                        medicine.setMedicine_number(number);
                                                        medicine.setMedicine_thd(thd);
                                                        if (medicineBiz.addMedicine(medicine)){
                                                            System.out.println("添加成功");
                                                            break;
                                                        }else {
                                                            System.out.println("添加失败");
                                                            break;
                                                        }
                                                    case 2:
                                                        System.out.println("0 修改数量");
                                                        System.out.println("1 修改价格");
                                                        Scanner s4=new Scanner(System.in);
                                                        int kc2=s4.nextInt();
                                                        switch (kc2){
                                                            case 0:
                                                                Scanner s5=new Scanner(System.in);
                                                                System.out.println("请输入需更新的药品名称：");
                                                                String name1=s5.nextLine();
                                                                System.out.println("请输入需更新药品的日期（xxxx-xx-xx格式）：");
                                                                String  date2=s5.nextLine();
                                                                DateTimeFormatter df1=DateTimeFormatter.ofPattern(date2);
                                                                LocalDate date3=LocalDate.parse(date2,df1);
                                                                System.out.println("请输入更新后的药品数量");
                                                                int number1=s5.nextInt();
                                                                if(medicineBiz.changeNumber(name1,date3,number1)){
                                                                    System.out.println("更新成功");
                                                                    break;
                                                                }else {
                                                                    System.out.println("更新失败");
                                                                    break;
                                                                }
                                                            case 1:
                                                                Scanner sc=new Scanner(System.in);
                                                                System.out.println("请输入要修改价格的药品名：");
                                                                String name2=sc.nextLine();
                                                                System.out.println("请输入修改后的药品价格：");
                                                                double price1=sc.nextInt();
                                                                if(medicineBiz.changePrice(name2,price1)){
                                                                    System.out.println("修改成功");
                                                                    break;
                                                                }else {
                                                                    System.out.println("修改失败");
                                                                    break;
                                                                }
                                                        }
                                                        break;
                                                }
                                                break;
                                            case 2:
                                                System.out.println("0 查询药品数量");
                                                System.out.println("1 查询近效期药品情况");
                                                System.out.println("2 查询过期药品情况");
                                                int kc2=scanner.nextInt();
                                                switch (kc2){
                                                    case 0:
                                                        System.out.println("请输入你要查询的药品的名称：");
                                                        Scanner s1=new Scanner(System.in);
                                                        String medicinename=s1.nextLine();
                                                        List<Medicine> list=medicineBiz.qurryMedicineNumberByName(medicinename);
                                                        for (Medicine medicine:list){
                                                            System.out.println(medicinename+"的总数量为"+medicine.getMedicine_number()+"份");
                                                        }
                                                        break;
                                                    case 1:
                                                        List<Medicine> list1=medicineBiz.checkNearTermMedicine();
                                                        for (Medicine medicine:list1){
                                                            System.out.println(medicine.getMedicine_number()+"份"+medicine.getMedicine_name()+"将于"+medicine.getMedicine_date()+"到期");
                                                        }
                                                        break;
                                                    case 2:
                                                        List<Medicine> list2=medicineBiz.checkMedicineDateBeformNow();
                                                        for (Medicine medicine:list2){
                                                            System.out.println(medicine.getMedicine_number()+"份"+medicine.getMedicine_name()+"已于"+medicine.getMedicine_date()+"到期");
                                                        }
                                                        break;
                                                }
                                                break;
                                        }
                                    }

                                    break;
                                default:
                                    break;
                            }
                        }else if (emp.getEmp_status().equals("禁用")){
                            System.out.println("你的账号被禁用了，请到系统管理员处激活账号");
                        }
                    }
                    else {
                        System.out.println("账号或密码错误，请重新登录");
                    }
                    break;
                case 0:
                    a=false;
                    break;
                default:
                    System.out.println("无效操作！");
                    break;
            }
        }
    }
}


